package com.sky.mapper;

//import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.Page;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper{

    @Select("select * from dish where id = #{id}")
    Dish getDishById(Long id);

    /**
     * 根据id查询菜品
     *
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    DishVO getById(Long id);

    /**
     * 根据分类id查询菜品
     *
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id=#{categoryId}")
    List<Dish> getByCategoryId(Long categoryId);

    /**
     * 菜品分页查询
     *
     * @param dto
     * @return
     */
    //@Select("select * from dish")
    Page<DishVO> getByPage(DishPageQueryDTO dto);

    /**
     * 菜品起售、停售
     *
     * @param status
     * @param id
     */
    @Update("update sky_take_out.dish set status=#{status} where id=#{id}")
    void updateStatus(Integer status, Long id);

    /**
     * 新增菜品
     *
     * @param dish
     */
    // 补齐数据
    @Options(keyProperty = "id",useGeneratedKeys = true)
    @Insert("insert into sky_take_out.dish values (null,#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void add(Dish dish);

    /**
     * 根据id删除菜品
     * @param id
     */
    @Delete("delete from sky_take_out.dish where id=#{id}")
    void delete(Long id);

    /**
     * 更新菜品
     * @param dish
     */
    void update(Dish dish);
}
